package b2.scene.fight
{
	import com.greensock.*;
	
	import flash.display.Sprite;
	import flash.filters.*;
	import flash.text.*;

	public class PopNumberEffect extends Sprite
	{
		private var numText:TextField;
		 
		public function PopNumberEffect(number:int, fontSize:int = 20, fontColor:int = 0xFF0000, outlineColor:int = 0xFFFF00, leftDirection:Boolean = false)
		{
			super();
			numText = new TextField();
			numText.selectable = false;
        	numText.autoSize = TextFieldAutoSize.LEFT;
			numText.defaultTextFormat = new TextFormat("微软雅黑", fontSize, fontColor, true);
			numText.filters = [new GlowFilter(outlineColor, 1, 1.3, 1.3, 100, BitmapFilterQuality.HIGH)];
			if (number > 0)
				numText.text = "+" + number;
			else
				numText.text = number.toString();
			addChild(numText);
			if (leftDirection)
				TweenLite.to(numText, 0.5, {x: -40, y: -70, scaleX:1.8, scaleY:1.8, onComplete: onEffectComplete});
			else
				TweenLite.to(numText, 0.5, {x: 40, y: -70, scaleX:1.8, scaleY:1.8, onComplete: onEffectComplete});
		}
		
		private function destroy():void
		{
			if (numText != null && numText.parent != null)
			{
				numText.parent.removeChild(numText);
				numText = null;
			}
			if (this.parent != null)
				this.parent.removeChild(this);
		}
		
		private function onEffectComplete():void
		{
			destroy();
		}
		
	}
}